//json转树形
const jsonToTree = function(data, type, childrenType, childrenName) {

	data.forEach(function(item) {
		delete item[childrenName]
	});
	var map = {};
	data.forEach(function(item) {
		map[item[type]] = item
	});
	var val = [];
	data.forEach(function(item) {

		var parent = map[item[childrenType]];

		if (parent) {
			(parent[childrenName] || (parent[childrenName] = [])).push(item)
		} else {
			val.push(item)
		}
	});
	return val
};
const treeToJson = function(arr, type) {
	const cache = [];
	for (const t of arr) {
		if (cache.find(c => c[type] === t[type])) {
			continue
		}
		cache.push(t)
	}
	return cache
};
export {
	jsonToTree,
	treeToJson
};
